import cv2
import numpy as np

img = cv2.imread('img/example.png')

h, w, c = img.shape

gray_img = np.arange(h * w, dtype=np.uint8).reshape(h, w)

for i in range(h):
    for j in range(w):
        gray_img[i, j] = max(img[i, j][0], img[i, j][1], img[i, j][2])

cv2.imshow('', gray_img)
cv2.waitKey(0)